package besteAukera;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

public class Multiplexorea extends Konbinazionalak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea = new Vector<Hanka>();
	private Vector<Hanka> sarreraBektorea = new Vector<Hanka>();
	private Hanka s1, s2, i1, s4, s3, s5, s6, s7;

	public Multiplexorea(int x1, int y1, int hankaKop, int sarreraKopMax,
			String mota, Color kolorea) {
		super(x1, y1, hankaKop, sarreraKopMax, mota, kolorea);
		// TODO Auto-generated constructor stub

		if (this.mota .compareTo("lau")==0) {
			s1 = new Hanka(x - 20, y + 20, "positiboa", "s", 0, this, "h", "ez",false);
			s2 = new Hanka(x - 20, y + 60, "positiboa", "s", 1, this, "h", "ez",false);
			i1 = new Hanka(x + 60, y + 40, "positiboa", "i", 4, this, "h", "ez",false);
			// kontrola
			s3 = new Hanka(x + 20, y + 80, "positiboa", "s", 2, this, "b",
					"bai",true);
			// Gaikuntza
			s4 = new Hanka(x + 20, y, "negatiboa", "s", 3, this, "b", "ez",true);

			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = i1;
		}
		if (this.mota.compareTo("zortzi")==0) {
			s1 = new Hanka(x - 20, y + 12, "positiboa", "s", 0, this, "h", "ez",false);
			s2 = new Hanka(x - 20, y + 30, "positiboa", "s", 1, this, "h", "ez",false);
			s3 = new Hanka(x - 20, y + 48, "positiboa", "s", 2, this, "h", "ez",false);
			s4 = new Hanka(x - 20, y + 66, "positiboa", "s", 3, this, "h", "ez",false);
			i1 = new Hanka(x + 60, y + 40, "positiboa", "i", 7, this, "h", "ez",false);
			// kontrola
			s5 = new Hanka(x + 15, y + 85, "positiboa", "s", 4, this, "b",
					"bai",true);
			s6 = new Hanka(x + 28, y + 73, "positiboa", "s", 5, this, "b",
					"bai",true);
			// Gaikuntza
			s7 = new Hanka(x + 20, y, "negatiboa", "s", 6, this, "b", "ez",true);

			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = s5;
			lotList[5] = s6;
			lotList[6] = s7;
			lotList[7] = i1;

		}
	}

	public void marraztu(Graphics g) {
		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		// goikoa
		g.drawLine(x, y, x, y + 80);
		g.drawLine(x, y, x + 40, y + 40);
		g.drawLine(x, y + 80, x + 40, y + 40);

		if (this.mota.compareTo("lau")==0) {
			s1.marraztu(g);
			s2.marraztu(g);
			s4.marraztu(g);
			s3.marraztu(g);
			i1.marraztu(g);
			g.setColor(Color.black);
			g.drawString("2:1", x + 10, y + 45);
		}
		if (this.mota.compareTo("zortzi")==0) {
			s1.marraztu(g);
			s2.marraztu(g);
			s4.marraztu(g);
			s3.marraztu(g);
			i1.marraztu(g);
			s5.marraztu(g);
			s6.marraztu(g);
			s7.marraztu(g);
			g.setColor(Color.black);
			g.drawString("4:1", x + 10, y + 45);
		}
	}

	public boolean barruanDago(int x, int y) {
		if ((x > this.x) && (x < (this.x + 40)) && (y > this.y+10)
				&& (y < (this.y + 70))) {
			return true;
		}
		return false;

	}

	@Override
	public void funtzioLogikoa(Integer... values) {

		// TODO Auto-generated method stub

		if (this.mota.compareTo("lau")==0) {
			if (lotList[3].getSarrera().getBalioa().compareTo(1)==0)
		
			lotList[4].getIrteera().setBalioa(lotList[s3.getSarrera().getBalioa()].getSarrera().getBalioa());
		}
		if (this.mota.compareTo("zortzi")==0) {
			

			if (lotList[6].getSarrera().getBalioa().compareTo(1)==0)
			lotList[7].getIrteera().setBalioa(lotList[s5.getSarrera().getBalioa()*2+s6.getSarrera().getBalioa()].getSarrera().getBalioa());

		}
	}

	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub

		if (this.mota.compareTo("zortzi")==0) {
			hankaBektorea = new Vector<Hanka>();
			hankaBektorea.addElement(s1);
			hankaBektorea.addElement(s2);
			hankaBektorea.addElement(s3);
			hankaBektorea.addElement(s4);
			hankaBektorea.addElement(s5);
			hankaBektorea.addElement(s6);
			hankaBektorea.addElement(s7);
			hankaBektorea.addElement(i1);
		}
		if (this.mota.compareTo("lau")==0) {
			hankaBektorea = new Vector<Hanka>();
			hankaBektorea.addElement(s1);
			hankaBektorea.addElement(s2);
			hankaBektorea.addElement(s3);
			hankaBektorea.addElement(s4);
			hankaBektorea.addElement(i1);
		}
		return hankaBektorea;
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		if (this.mota.compareTo("zortzi")==0) {
			sarreraBektorea = new Vector<Hanka>();
			sarreraBektorea.addElement(s1);
			sarreraBektorea.addElement(s2);
			sarreraBektorea.addElement(s3);
			sarreraBektorea.addElement(s4);
			sarreraBektorea.addElement(s5);
			sarreraBektorea.addElement(s6);
			sarreraBektorea.addElement(s7);
		}
		if (this.mota.compareTo("lau")==0) {
			sarreraBektorea = new Vector<Hanka>();
			sarreraBektorea.addElement(s1);
			sarreraBektorea.addElement(s2);
			sarreraBektorea.addElement(s3);
			sarreraBektorea.addElement(s4);

		}
		return sarreraBektorea;
	}
	public static int Potencia (int Base, int Exponente){
		int Ret = 1;
		for (int i = 0; i < Exponente; ++i)
		Ret *= Base;
		return Ret;
		}
}
